package com.pearadmin.pro.modules.paper.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.context.UserContext;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.exam.dto.request.PaperQuQueryDTO;
import com.pearadmin.pro.modules.examUtils.PagingReqDTO;
import com.pearadmin.pro.modules.examUtils.dto.BaseIdReqDTO;
import com.pearadmin.pro.modules.examUtils.dto.BaseIdRespDTO;
import com.pearadmin.pro.modules.examUtils.dto.BaseIdsReqDTO;
import com.pearadmin.pro.modules.paper.dto.RepoDTO;
import com.pearadmin.pro.modules.paper.dto.ext.PaperQuDetailDTO;
import com.pearadmin.pro.modules.paper.dto.request.PaperAnswerDTO;
import com.pearadmin.pro.modules.paper.dto.request.PaperCreateReqDTO;
import com.pearadmin.pro.modules.paper.dto.request.PaperListReqDTO;
import com.pearadmin.pro.modules.paper.dto.response.ExamDetailRespDTO;
import com.pearadmin.pro.modules.paper.dto.response.ExamResultRespDTO;
import com.pearadmin.pro.modules.paper.dto.response.PaperListRespDTO;
import com.pearadmin.pro.modules.paper.dto.response.RepoRespDTO;
import com.pearadmin.pro.modules.paper.entity.Repo;
import com.pearadmin.pro.modules.paper.service.PaperService;
import com.pearadmin.pro.modules.paper.service.QuRepoService;
import com.pearadmin.pro.modules.paper.service.RepoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 题库控制器
 *
 * @author ZhouXingYun
 * @date 2022/5/23 17:21
 */

@Api(tags = {"题库"})
@RestController
@RequestMapping(ControllerConstant.PREFIX_SYS + "repo")
public class RepoController extends BaseController {

    @Autowired
    private RepoService baseService;

    @Autowired
    private QuRepoService quRepoService;


    /**
     * 分页查找
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找题库")
    @Log(title = "分页查找题库")
    @RequestMapping(value = "/paging", method = { RequestMethod.POST})
    public Result<IPage<RepoRespDTO>> paging(@RequestBody PagingReqDTO<RepoDTO> reqDTO) {
        //分页查询并转换
        IPage<RepoRespDTO> page = baseService.paging(reqDTO);
        return success(page);
    }
    @ApiOperation(value = "查询所有题库")
    @Log(title = "查询所有题库")
    @RequestMapping(value = "/getRepo", method = { RequestMethod.POST})
    public Object getRepo() {
        //分页查询并转换
        List<Repo> list = baseService.list(null);
        if(list!= null && list.size()>0){
            for (Repo repo : list) {
                repo.setLabel(repo.getTitle());
                repo.setValue(repo.getId());
            }
        }
        return success(list);
    }
   /**
    * 题库添加或修改
    * @author ZhouXingYun
    * @date 2022/5/30 17:00
    * @param reqDTO
    * @return ApiRest
    */
    @ApiOperation(value = "题库添加或修改")
    @Log(title = "题库添加或修改")
    @RequestMapping(value = "/save", method = { RequestMethod.POST})
    public Result save(@RequestBody RepoDTO reqDTO) {
        baseService.save(reqDTO);
        return success();
    }
/**
 * 批量删除题库
 * @author ZhouXingYun
 * @date 2022/5/30 18:41
 * @param reqDTO
 * @return com.pearadmin.pro.common.web.domain.Result
 */
    @ApiOperation(value = "批量删除题库")
    @Log(title = "批量删除题库")
    @RequestMapping(value = "/delete", method = { RequestMethod.POST})
    public Result edit(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        baseService.removeByIds(reqDTO.getIds());
        return success();
    }
}
